package com.hui.server.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.hui.server.config.redis.RedisCacheConfig;
import com.hui.server.entity.Role;
import org.apache.ibatis.annotations.CacheNamespace;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;


/**
 * <p>
 *  Mapper 接口，开启缓存
 * </p>
 *      mybatis-plus 注解形式多对多查询
 * @author hui
 * @since 2022-03-31
 */

//@CacheNamespace(implementation = RedisCacheConfig.class)
public interface RoleMapper extends BaseMapper<Role> {

    /**
     *  根据菜单menu Id 查询角色，子查询，MenuMapper对应父查询方法：getMenusByRoles()
     * @param id
     * @return
     */
    @Select("select \n" +
            "distinct r.*\n" +
            "from \n" +
            "t_role r,\n" +
            "t_menu_role mr,\n" +
            "t_menu m\n" +
            "where\n" +
            "r.id =mr.rid\n" +
            "and\n" +
            "mr.mid =#{id}")
    List<Role> getRoleByMenuId(@Param("id") Integer id);


    /**
     * 根据用户ID查询角色列表
     * @param adminId
     * @return
     */
    @Select("select \n" +
            " r.id,r.`name`,r.nameZh\n" +
            "from \n" +
            "t_role r,\n" +
            "t_admin_role ar\n" +
            "where\n" +
            "r.id =ar.rid\n" +
            "AND\n" +
            "ar.adminId =#{adminId}\n")
    List<Role> getRolesByAdminId(@Param("adminId") Integer adminId);




}
